package com.epfresh.supplier.entity;

import java.util.ArrayList;
import java.util.List;

public class StoreDeliveryCityCityService extends TagEntity {
    private String code;

    private List<CityDeliveryWay> cityPaymentList;
    private List<CityDeliveryWay> cityDeliveryList;
    private List<CityDeliveryWay> cityPayment = new ArrayList<>();
    private boolean isChecked;

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public List<CityDeliveryWay> getCityPayment() {
        return cityPaymentList;
    }

    public void setCityPayment(List<CityDeliveryWay> cityPayment) {
        this.cityPaymentList = cityPayment;
    }

    public List<CityDeliveryWay> getCityDeliveryList() {
        return cityDeliveryList;
    }

    public void setCityDeliveryList(List<CityDeliveryWay> cityDeliveryList) {
        this.cityDeliveryList = cityDeliveryList;
    }


    public String getCityDelivery() {
        String s = "";
        String gatherDistribution = null;
        String selfDelivery = null;
        if (cityDeliveryList != null) {
            for (int i = 0; i < cityDeliveryList.size(); i++) {
                CityDeliveryWay cityDeliveryWay = cityDeliveryList.get(i);

                if ("gatherDistribution".equals(cityDeliveryWay.getCode())) {
                    gatherDistribution = cityDeliveryWay.getName();
                } else if ("selfDelivery".equals(cityDeliveryWay.getCode())) {
                    selfDelivery = cityDeliveryWay.getName();
                }
            }
        }

        if (gatherDistribution != null) {
            s = gatherDistribution;
        }

        if (selfDelivery != null) {
            if (gatherDistribution != null) {
                s += ",";
            }

            s += selfDelivery;
        }

        return s;
    }
    public String getPaymentStr() {
        String s = "";
        String gatherDistribution = null;
        String selfDelivery = null;
        if (cityPaymentList != null) {
            for (int i = 0; i < cityPaymentList.size(); i++) {
                CityDeliveryWay cityDeliveryWay = cityPaymentList.get(i);

                if ("onlinePayment".equals(cityDeliveryWay.getCode())) {
                    gatherDistribution = cityDeliveryWay.getName();
                } else if ("cashOnDelivery".equals(cityDeliveryWay.getCode())) {
                    selfDelivery = cityDeliveryWay.getName();
                }
            }
        }

        if (gatherDistribution != null) {
            s = gatherDistribution;
        }

        if (selfDelivery != null) {
            if (gatherDistribution != null) {
                s += ",";
            }

            s += selfDelivery;
        }

        return s;
    }

    public void mergePayment() {

        int payOnline = 0;
        int payOffline = 0;

        CityDeliveryWay cityPaymentOnline = null;
        CityDeliveryWay cityPaymentOffline = null;
        if (cityDeliveryList != null) {
            for (int i = 0; i < cityPaymentList.size(); i++) {
                CityDeliveryWay cityPayment = cityPaymentList.get(i);

                if (cityPayment != null) {
                    if ("onlinePayment".equals(cityPayment.getCode())) {
                        payOnline++;
                        cityPaymentOnline = cityPayment;
                    } else if ("cashOnDelivery".equals(cityPayment.getCode())) {
                        payOffline++;
                        cityPaymentOffline = cityPayment;
                    }
                }

            }
        }

        if (payOnline > 0 ) {
            cityPayment.clear();
            cityPayment.add(cityPaymentOnline);
            if (payOnline == payOffline){
                cityPayment.add(cityPaymentOffline);
            }
        }
    }

    public List<CityDeliveryWay> getPayment() {

        return cityPayment;
    }

    public void setPayment(List<CityDeliveryWay> cityPayment) {
        this.cityPayment = cityPayment;
    }
}
